package com.augmentum.oes.service.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.augmentum.oes.dao.mybatis.QuestionDaoImpl;
import com.augmentum.oes.model.Pagination;
import com.augmentum.oes.model.Question;
import com.augmentum.oes.service.QuestionService;

@Service
public class QuestionServiceImpl implements QuestionService {
    @Autowired
    private QuestionDaoImpl questionDao;

    @Override
    public Question getById(int id) {
        return questionDao.queryById(id);
    }

    @Override
    public void changeQ(Question question) {
        questionDao.updateQ(question);
    }

    @Override
    public List<Question> dealPage(Pagination<Question> page) {
        int pageCount = questionDao.getCount(page.getFuzzyWord());
        page.setTotalCount(pageCount);
        return questionDao.queryQuestionPage(page);
    }

    @Override
    public void dealBatch(String idBatch) {
        String[] idSplit = idBatch.split(",");
        for (String id : idSplit) {
            if (id.matches("[0-9]*")) {
                questionDao.deleteQ(Integer.parseInt(id));
            } else {
                return;
            }
        }
    }

    @Override
    public void createQ(Question question) {
        questionDao.createQuestion(question);
    }

    @Override
    public void deleteQ(int id) {
        questionDao.deleteQ(id);
    }
}
